#include "const.h"

const char *getconfigdir() {
#ifdef _WIN32
	static char buf[MAX_PATH] = { 0, };
	size_t i;
#else
	static char buf[PATH_MAX] = { 0, };
#endif
	char *p;

	if (buf[0] != 0)
		return buf;

#if defined(_WIN32)
	GetModuleFileNameA(NULL, buf, sizeof(buf));

	if (buf[1]==':') {
		if (buf[0]>='A'&&buf[0]<='Z')
			buf[0] = buf[0] - 'A' + 'a';
	}

	for(i=0; i<sizeof(buf); i++) {
		if (buf[i]=='\\')
			buf[i] = '/';
	}

	if (!(p = strrchr(buf, '/')))
		i_interror("something is wrong with GetModuleFileNameA");

	p[1] = 0;

	i_strcat(buf, sizeof(buf), "config/");
#elif defined(linux)||defined(__linux)||defined(__linux__)
	i_strcat(buf, sizeof(buf), "/etc/builder/");
#elif defined(__APPLE__)
	i_strcat(buf, sizeof(buf), "/etc/builder/");
#else
	// !!! YOU NEED TO SPECIFY THE PROPER CONFIG DIR HERE !!!
	// make sure it ends in "/" too
	i_strcat(buf, "./config/");
#endif

	mkdirs(buf);
	return buf;
}
